<?php


namespace Home\Model;
use Think\Model;

class UserModel extends Model
{
    protected $_map=[
        'email'=>'user_email',
        'qq'=>'user_qq',
        'tel'=>'user_tel',
        'sex'=>'user_sex',
        'edu'=>'user_xueli',
        'hobbies'=>'user_hobby',
        'introduce'=>'user_introduce',
    ];//当表单名称与数据库字段名称不对应时，需进行字段映射
    protected $_validate=[
        ['username','require','用户名必须填写',1],
        ['username','','用户名已存在',1,'unique'],
        ['password','require','密码必须填写',1],
        ['password','6,10','密码长度错误',1,'length'],
        ['re_password','require','确认密码必须填写',1],
        ['password','re_password','两次密码需一致',1,'confirm'],
        ['user_email','email','邮箱格式错误',1],
        ['user_qq','5,11','qq位数超限',1,'length'],
        ['user_tel','/^1[34578]\d{9}$/','手机号错误',1,'regex'],
        ['user_xueli','1,3','学历必须为初中以上',1,'between'],
        ['user_hobby','check_hobby','爱好必选两项以上',1,'callback'],
        ['user_introduce','require','简介需写',1],
    ];
    public function check_hobby($data){
        if(count($data)<2){
            return false;
        }
        return true;
    }
}